using System;
namespace Net35.Xrm.Sdk.Client
{
	internal sealed class OrganizationServiceContextInitializer : ServiceContextInitializer<IOrganizationService>
	{
		private OrganizationServiceProxy OrganizationServiceProxy
		{
			get
			{
				return base.ServiceProxy as OrganizationServiceProxy;
			}
		}
		public OrganizationServiceContextInitializer(OrganizationServiceProxy proxy) : base(proxy)
		{
			this.Initialize();
		}
		private void Initialize()
		{
			if (this.OrganizationServiceProxy != null)
			{
				if (this.OrganizationServiceProxy.OfflinePlayback)
				{
					System.ServiceModel.OperationContext.Current.OutgoingMessageHeaders.Add(System.ServiceModel.Channels.MessageHeader.CreateHeader("IsOfflinePlayback", "http://schemas.microsoft.com/xrm/2011/Contracts", true));
				}
				if (this.OrganizationServiceProxy.CallerId != Guid.Empty)
				{
					System.ServiceModel.OperationContext.Current.OutgoingMessageHeaders.Add(System.ServiceModel.Channels.MessageHeader.CreateHeader("CallerId", "http://schemas.microsoft.com/xrm/2011/Contracts", this.OrganizationServiceProxy.CallerId));
				}
				if (this.OrganizationServiceProxy.LanguageCodeOverride != 0)
				{
					System.ServiceModel.OperationContext.Current.OutgoingMessageHeaders.Add(System.ServiceModel.Channels.MessageHeader.CreateHeader("LanguageCodeOverride", "http://schemas.microsoft.com/xrm/2011/Contracts", this.OrganizationServiceProxy.LanguageCodeOverride));
				}
				if (this.OrganizationServiceProxy.SyncOperationType != null)
				{
					System.ServiceModel.OperationContext.Current.OutgoingMessageHeaders.Add(System.ServiceModel.Channels.MessageHeader.CreateHeader("OutlookSyncOperationType", "http://schemas.microsoft.com/xrm/2011/Contracts", this.OrganizationServiceProxy.SyncOperationType));
				}
				if (!string.IsNullOrEmpty(this.OrganizationServiceProxy.ClientAppName))
				{
					System.ServiceModel.OperationContext.Current.OutgoingMessageHeaders.Add(System.ServiceModel.Channels.MessageHeader.CreateHeader("ClientAppName", "http://schemas.microsoft.com/xrm/2011/Contracts", this.OrganizationServiceProxy.ClientAppName));
				}
				if (!string.IsNullOrEmpty(this.OrganizationServiceProxy.ClientAppVersion))
				{
					System.ServiceModel.OperationContext.Current.OutgoingMessageHeaders.Add(System.ServiceModel.Channels.MessageHeader.CreateHeader("ClientAppVersion", "http://schemas.microsoft.com/xrm/2011/Contracts", this.OrganizationServiceProxy.ClientAppVersion));
				}
				if (!string.IsNullOrEmpty(this.OrganizationServiceProxy.SdkClientVersion))
				{
					System.ServiceModel.OperationContext.Current.OutgoingMessageHeaders.Add(System.ServiceModel.Channels.MessageHeader.CreateHeader("SdkClientVersion", "http://schemas.microsoft.com/xrm/2011/Contracts", this.OrganizationServiceProxy.SdkClientVersion));
					return;
				}
				string xrmSdkAssemblyFileVersion = this.OrganizationServiceProxy.GetXrmSdkAssemblyFileVersion();
				if (!string.IsNullOrEmpty(xrmSdkAssemblyFileVersion))
				{
					System.ServiceModel.OperationContext.Current.OutgoingMessageHeaders.Add(System.ServiceModel.Channels.MessageHeader.CreateHeader("SdkClientVersion", "http://schemas.microsoft.com/xrm/2011/Contracts", xrmSdkAssemblyFileVersion));
				}
			}
		}
	}
}
